package com.example.houduan.service;

import com.example.houduan.domain.User;
import com.example.houduan.domain.UserExample;
import com.example.houduan.mapper.UserMapper;
import com.example.houduan.rep.Replogin;
import com.example.houduan.resp.Resplogin;
import com.example.houduan.utils.CopyUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;
@Service
public class Userservice {
    @Resource
    public UserMapper userMapper;
    public Resplogin login(Replogin req)
    {
        User user=selectByLoginName(req.getUid());
        if (ObjectUtils.isEmpty(user))
        {
            return null;
        }else {
            if(req.getPassword().equals(user.getPassword()))
            {
                Resplogin resplogin= CopyUtil.copy(user, Resplogin.class);
                return resplogin;
            }
        }
        return null;
    }
    public User selectByLoginName(String uid)
    {
        UserExample userExample=new UserExample();
        UserExample.Criteria criteria=userExample.createCriteria();
        criteria.andUidEqualTo(uid);
        List<User> users=userMapper.selectByExample(userExample);
        if(CollectionUtils.isEmpty(users)){
            return null;
        }else{
            return users.get(0);
        }

    }

}
